home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10490 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: scoshe@ix.netcom.com(Christopher Scott Shelton )
  3. Newsgroups: comp.lang.c
  4. Subject: HELP!! with file read/write
  5. Date: 18 Mar 1996 03:01:37 GMT
  6. Organization: Netcom
  7. Message-ID: <4iijmh$brs@cloner2.ix.netcom.com>
  8. NNTP-Posting-Host: atl-ga18-01.ix.netcom.com
  9. X-NETCOM-Date: Sun Mar 17  7:01:37 PM PST 1996
  10.  
  11.  
  12. This part of my program should read a record, decrease daysleft by one,
  13. and set today equal to zero and re-write the data at the original
  14. position.
  15. For some reason it does one read, the following write and then it exits
  16. out.
  17. I know that it should run 4 times.  Can anyone help me with this
  18. problem.
  19.  
  20. Thanks,
  21. Scott.....
  22. ---------------------------------
  23.  
  24. void daily_maintainence()
  25. {
  26.   FILE *itemfile;
  27.   long  filepos;
  28.   struct _items item;
  29.   itemfile=fopen("items.dat","r+b");          //open for read and write
  30.   while (fread(&item,itemsize,1,itemfile)==1)
  31.   {
  32.     filepos=ftell(itemfile);                  //for debug
  33.     item.today=0;                             //set to zero
  34.     item.daysleft--;                          //decrement
  35.     fseek(itemfile,-itemsize,SEEK_CUR);       //seek to where this rec
  36. starts
  37.     filepos=ftell(itemfile);                  //for debug
  38.     fwrite(&item,itemsize,1,itemfile);        //write it out
  39.     filepos=ftell(itemfile);                  //for debug
  40.   }
  41. }
  42. ------------------------
  43.  
  44.  
  45.  
  46.  
  47.